CreateConVar("rlevel_startxp",250,true,false)
CreateConVar("rlevel_xpinc",50,true,false)
CreateConVar("rlevel_adv",1,true,false)

exp_start = GetConVarNumber("rlevel_startxp")
exp_inc = GetConVarNumber("rlevel_xpinc")

function GetXpFromHighlevel( victim, killer )


end

function AddXp( pl , ammount )

local currentxp = pl:GetNWInt("xp")
	local ammount = ammount + currentxp
		pl:SetNWInt("xp",ammount)

end

function Addlevel( pl , ammount )

local currentxp = pl:GetNWInt("level")
	local ammount = ammount + currentxp
		pl:SetNWInt("level",ammount)


end

function AddCredits( pl , ammount )

local currentxp = pl:GetNWInt("credits")
	local ammount = ammount + currentxp
		pl:SetNWInt("credits",ammount)

end

function CalcExpInc(level)
	if(level < 1) then
		exp = GetConVarNumber("rlevel_startxp")
		return exp
	else
		exp = ((level*GetConVarNumber("rlevel_startxp"))+GetConVarNumber("rlevel_xpinc"))

	return exp
	end
	
end



function DoLevelUp( player, text, xp, credits, level )

		player:SetNWInt("xp",xp)
		player:SetNWInt("credits",credits)
		player:SetNWInt("level",level)
		player:ChatPrint("[RLevel- FOR BETA]"..text)// error ChatPrint a nil value ?=
		player:SetNWInt("rxp",CalcExpInc(player:GetNWInt("level")))
		RunConsoleCommand("play","levelup.wav")

end

function CalcLevelUp( pl )// GM:Think

local exp = pl:GetNWInt("xp")
local level = pl:GetNWInt("level")
local nec = pl:GetNWInt("credits")
	exp_req = CalcExpInc(level)
			if( exp >= exp_req ) then
					  level = level + 1
					exp =  exp - exp_req
				  nec = nec + 50
		DoLevelUp( pl, "Du bist auf Level "..level.." XP: "..exp.."/"..exp_req..".", exp, nec, level )
	end
end


function PlayerKill(Victim, Inflictor, Attacker)
if(Victim == Attacker) then

else
 local exp = Attacker:GetNWInt("xp")
 if(Attacker:GetNWInt("level") <= Victim:GetNWInt("level") ) then
	 exp = math.Round((exp + GetConVarNumber("rlevel_xpinc")))
 elseif(Attacker:GetNWInt("level") >= Victim:GetNWInt("level")) then
	exp = math.Round((exp + GetConVarNumber("rlevel_xpinc")))
end
 Attacker:SetNWInt("xp",exp)
end
end


function PlayerDamageXp(victim, attacker , amount , dmginfo  )

local Victimlevel = victim:GetNWInt("level")
local constmultiplicator = 15


	--if( attacker:Team() == victim:Team() ) then return end
	if( attacker == victim ) then return end
		

/*if( weapon == XX ) then end*/

constmultiplicator = math.Round((constmultiplicator+Victimlevel)*(amount/100))
AddXp( attacker , constmultiplicator)



end

Msg("Player functions was loaded\n")